#pragma once

#include <iosfwd>

template<typename T>
void Persist(std::ostream& os,T const& value)
{
	os.write((char const*)&value,sizeof(T));
}

void Persist(std::ostream& os, std::string const& value)
{
	size_t size = value.size();
	os.write((char const*)&size,sizeof(size_t));
	os.write(value.c_str(),size);	
}

template<typename T>
void Persist(std::ostream& os , std::vector<T> const& value)
{
	size_t size = value.size();
	os.write((char const*)&size,sizeof(size_t));
	for (size_t i = 0; i < value.size(); ++i)
	{
		Persist(os,value[i]);
	}
}

template<typename T>
void Persist(std::istream& is, T& value)
{
	is.read((char*)&value,sizeof(T));
}

void Persist(std::istream& is, std::string& value)
{
	size_t size = 0;
	Persist(is,size);
	value.resize(size);
	is.read(&value[0],size);
}


template<typename T>
void Persist(std::istream& is, std::vector<T>& value)
{
	size_t size = 0;
	Persist(is,size);
	for (size_t i = 0; i < size; ++i)
	{
		T v;
		Persist(is,v);
		value.push_back(v);
	}
}